#include "DebugDrawLightsFX.h"

DebugDrawLightsFX::DebugDrawLightsFX(ID3D11Device* device)
	: AbstractFX(device, L"FX/DebugDrawLights.fxo") 
{
	//Call init functions
	InitInputLayout(device);
	InitShaderVariablePointers();
}

DebugDrawLightsFX::~DebugDrawLightsFX()
{}

void DebugDrawLightsFX::InitInputLayout(ID3D11Device* device)
{
	//Fillout input layout description.
	const D3D11_INPUT_ELEMENT_DESC inputLayout[] = 
	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
		//Per instance
		{"WORLD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{"WORLD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{"WORLD", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 32, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{"WORLD", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 48, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{"COLOUR",0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 64, D3D11_INPUT_PER_INSTANCE_DATA, 1}
	};

	//Create our input layout 	
	CreateInputLayout(device, inputLayout, 6);
}

void DebugDrawLightsFX::InitShaderVariablePointers()
{
	viewProjVar = effect->GetVariableByName("viewProj")->AsMatrix();
	eyePosVar = effect->GetVariableByName("EyePosW")->AsVector();
}

void DebugDrawLightsFX::SetViewProj(CXMMATRIX& vp)
{
	viewProjVar->SetMatrix(reinterpret_cast<const float*>(&vp));
}

void DebugDrawLightsFX::SetEyePos(XMFLOAT3& eye)
{
	eyePosVar->SetRawValue(&eye, 0, sizeof(XMFLOAT3));
}